import math
import random
from eden.ann.neurons import Neuron

if __name__ == "__main__":
	inputNeuron = Neuron()
	outputNeuron = Neuron()
	outputNeuron.addInput(inputNeuron, 0.1)
	Neuron.LEARNING_FACTOR = 0.1
	for i in range(100):
		input = random.choice((0, 1))
		expected = 1 if input == 1 else 0.5
		inputNeuron.setVoltage(input)
		outputNeuron.run()
		output = outputNeuron.getVoltage()
		weight = outputNeuron.getInputs()[inputNeuron]
		print('STEP#' + str(i) + ': ' + str(input) + ' --> ' + str(output) + ' (weight=' + str(weight) + ', LearningFactor=' + str(Neuron.LEARNING_FACTOR) + ')')
		Neuron.LEARNING_FACTOR = Neuron.LEARNING_FACTOR * 9 / 10 + math.fabs(expected - output) / 10
		outputNeuron.bp(expected)
